package 爬楼梯;

/**
 * createTime: 2025/4/28 23:41
 * description:
 *
 * @author AirMan
 */
public class Solution2 {
    public int climbStairs(int n) {
        // 优化dp数组


        if (n == 0 || n == 1)
            return n;

        int[] dp = new int[2];
        dp[0] = 1;
        dp[1] = 2;
//        System.out.println(Arrays.toString(dp));
        for (int i = 3; i <= n; i++) {
            int cutLevel = dp[0] + dp[1];
            dp[0] = dp[1];
            dp[1] = cutLevel;
//            System.out.println(Arrays.toString(dp));
        }
        return dp[1];
    }
}
